@page "/main"
@page "/"
@inject IJSRuntime js;
@using FOPS.Abstract.Fss.Server
@using FOPS.Abstract.MetaInfo.Server
@using FOPS.Abstract.Docker.Server
@using FOPS.Abstract.K8S.Server
@using FOPS.Abstract.Builder.Server
@inject IIocManager _iocManager;
@inject NavigationManager nav;
@inject Blazored.LocalStorage.ILocalStorageService storage;

<div class="layui-row layui-col-space15">
    <div class="layui-col-sm6 layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-header">
                集群
                <span class="layui-badge layui-bg-orange layuiadmin-badge">C</span>
            </div>
            <div class="layui-card-body layuiadmin-card-list">

                <p class="layuiadmin-big-font">@_clusterCount</p>
                <p>
                    K8S模板
                    <span class="layuiadmin-span-color">
                        @_yamlTplCount <i class="layui-inline layui-icon layui-icon-user"></i>
                    </span>
                </p>
            </div>
        </div>
    </div>
    <div class="layui-col-sm6 layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-header">
                项目
                <span class="layui-badge layui-bg-blue layuiadmin-badge">P</span>
            </div>
            <div class="layui-card-body layuiadmin-card-list">
                <p class="layuiadmin-big-font">@_projectCount</p>
                <p>
                    项目组
                    <span class="layuiadmin-span-color">
                        @_projectGroupCount <i class="layui-inline layui-icon layui-icon-flag"></i>
                    </span>
                </p>
            </div>
        </div>
    </div>
    <div class="layui-col-sm6 layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-header">
                容器
                <span class="layui-badge layui-bg-green layuiadmin-badge">D</span>
            </div>
            <div class="layui-card-body layuiadmin-card-list">

                <p class="layuiadmin-big-font">@_dockerHubCount</p>
                <p>
                    模板
                    <span class="layuiadmin-span-color">
                        @_dockerfileTplCount <i class="layui-inline layui-icon layui-icon-dollar"></i>
                    </span>
                </p>
            </div>
        </div>
    </div>
    <div class="layui-col-sm6 layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-header">
                构建
                <span class="layui-badge layui-bg-cyan layuiadmin-badge">月</span>
            </div>
            <div class="layui-card-body layuiadmin-card-list">
                <p class="layuiadmin-big-font">@_buildCount</p>
                <p>
                    Git仓库
                    <span class="layuiadmin-span-color">
                        @_gitCount <i class="layui-inline layui-icon layui-icon-face-smile-b"></i>
                    </span>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="layui-row layui-col-space15">
    <div class="layui-col-md8">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">FSS调度中心</div>
                    <div class="layui-card-body">
                        <div class="layui-carousel layadmin-carousel layadmin-backlog">
                            <div carousel-item>
                                <ul class="layui-row layui-col-space10 layui-this">
                                    <li class="layui-col-xs6">
                                        <navlink href="/fss/task_group/list" class="nav-link layadmin-backlog-body">
                                            <h3>FSS任务组</h3>
                                            <p>
                                                <cite>@_taskGroupCount</cite>
                                            </p>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs6">
                                        <navlink href="/fss/tasks/unrunlist" class="nav-link layadmin-backlog-body">
                                            <h3>超时未执行</h3>
                                            <p>
                                                <cite>@_toUnRunCount</cite>
                                            </p>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs6">
                                        <navlink href="/fss/client/list" class="nav-link layadmin-backlog-body">
                                            <h3>客户端</h3>
                                            <p>
                                                <cite>@_clientCount</cite>
                                            </p>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs6">
                                        <navlink href="/fss/tasks/faillist" class="nav-link layadmin-backlog-body">
                                            <h3>今日失败</h3>
                                            <p>
                                                <cite>@_todayFailCount</cite>
                                            </p>
                                        </navlink>
                                    </li>
                                </ul>
                                <ul class="layui-row layui-col-space10">
                                    <li class="layui-col-xs6">
                                        <a href="javascript:;" class="layadmin-backlog-body">
                                            <h3>待审友情链接</h3>
                                            <p>
                                                <cite style="color: #FF5722;">5</cite>
                                            </p>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">快捷方式</div>
                    <div class="layui-card-body">
                        <div class="layui-carousel layadmin-carousel layadmin-shortcut">
                            <div carousel-item>
                                <ul class="layui-row layui-col-space10 layui-this">
                                    <li class="layui-col-xs3">
                                        <navlink href="/builder/list">
                                            <i class="layui-icon layui-icon-console"></i>
                                            <cite>构建</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink href="/k8s/deploy/list">
                                            <i class="layui-icon layui-icon-chat"></i>
                                            <cite>POD发布</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink href="/k8s/single/deploy">
                                            <i class="layui-icon layui-icon-find-fill"></i>
                                            <cite>yaml发布</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink href="/project/list">
                                            <i class="layui-icon layui-icon-template-1"></i>
                                            <cite>项目设置</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink class="nav-link" href="/fss/task_group/list" Match="NavLinkMatch.All">
                                            <i class="layui-icon layui-icon-chart"></i>
                                            <cite>FSS任务组</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink class="nav-link" href="/fss/client/list" Match="NavLinkMatch.All">
                                            <i class="layui-icon layui-icon-set"></i>
                                            <cite>FSS客户端</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink href="/docker/tpl/list">
                                            <i class="layui-icon layui-icon-survey"></i>
                                            <cite>容器模板</cite>
                                        </navlink>
                                    </li>
                                    <li class="layui-col-xs3">
                                        <navlink href="/k8s/tpl/list">
                                            <i class="layui-icon layui-icon-user"></i>
                                            <cite>K8S模板</cite>
                                        </navlink>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md14">
                <div class="layui-card">
                    <div class="layui-card-header" id="anchor-play-header">
                        进行中的任务
                    </div>
                    <div class="layui-card-body">
                        <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1">
                            <div class="layui-table-box">
                                <TaskList PageSize="20"></TaskList>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-card">
            <div class="layui-card-header" id="anchor-play-header">
                构建队列
            </div>
            <div class="layui-card-body">
                <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1">
                    <div class="layui-table-box">
                        <BuildList></BuildList>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-header">版本信息</div>
            <div class="layui-card-body layui-text">
                <table class="layui-table">
                    <colgroup>
                        <col width="100">
                        <col>
                    </colgroup>
                    <tbody>
                    <tr>
                        <td>当前版本</td>
                        <td>
                            V1.0.0-beta.1
                        </td>
                    </tr>
                    <tr>
                        <td>基于框架</td>
                        <td>
                            .NET5 + Blazor
                        </td>
                    </tr>
                    <tr>
                        <td>主要特色</td>
                        <td>开发人员的运维管理平台</td>
                    </tr>
                    <tr>
                        <td>开源下载</td>
                        <td style="padding-bottom: 0;">
                            <div class="layui-btn-container">
                                <a href="https://github.com/FarseerNet/FOPS" target="_blank" class="layui-btn layui-btn-danger">Github</a>
                                <a href="https://gitee.com/FarseerNet/FOPS" target="_blank" class="layui-btn">Gitee</a>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

@code
{
    long _taskGroupCount;
    int _toUnRunCount;
    long _clientCount;
    int _todayFailCount;
    int _projectCount;
    int _projectGroupCount;
    int _gitCount;
    int _dockerHubCount;
    int _dockerfileTplCount;
    int _clusterCount;
    int _yamlTplCount;
    int _buildCount;

    protected override async Task OnInitializedAsync()
    {
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await js.InvokeVoidAsync("layuiConfig.use", "index", "console");
    // 初始化脚本
            
    // FSS 任务组数
            _taskGroupCount = await _iocManager.Resolve<IFssApi>().GetTaskGroupCountAsync(storage);
    // FSS 未执行数
            _toUnRunCount = await _iocManager.Resolve<IFssApi>().GetTaskGroupUnRunCountAsync(storage);
    // FSS 客户端数
            _clientCount = await _iocManager.Resolve<IFssApi>().GetClientCountAsync(storage);
    // FSS 今日失败数
            _todayFailCount = await _iocManager.Resolve<IFssApi>().TodayTaskFailCountAsync(storage);
    // 项目数量
            _projectCount = await _iocManager.Resolve<IProjectService>().CountAsync();
            _projectGroupCount = await _iocManager.Resolve<IProjectGroupService>().CountAsync();
    // Git数量
            _gitCount = await _iocManager.Resolve<IGitService>().CountAsync();

            _dockerHubCount = await _iocManager.Resolve<IDockerHubService>().CountAsync();
            _dockerfileTplCount = await _iocManager.Resolve<IDockerfileTplService>().CountAsync();

            _clusterCount = await _iocManager.Resolve<IClusterService>().CountAsync();
            _yamlTplCount = await _iocManager.Resolve<IYamlTplService>().CountAsync();

            _buildCount = await _iocManager.Resolve<IBuildService>().CountAsync();
            await InvokeAsync(StateHasChanged);
        }
    }
}